$:.unshift File.join(File.dirname(__FILE__), "..", "lib")

require 'UPnP/service/content_directory'
require 'UPnP/service/mythtv_content'
require 'builder'

#mock class to provide MySQL channel data 
class UPnP::Service::MythContainer
  def each_channel(sql_query)
    #chanid, channum, name, icon, starttime, endtime, title, subtitle, description, category
    [%w[1024 24 HDTV\ Super\ Channel /home/yuchem/.mythtv/channels/bell_expressvu.jpg 10:00 12:00 Test\ title],
     %w[1033 33 SD\ Normal\ Channel /home/yuchem/.mythtv/channels/equator_hd.jpg 10:30 11:30 Test\ title\ number two]
    ].each {|row| yield row}
  end
end

class TestMythItems < Test::Unit::TestCase
  class FakeWEBrickSocket
  
      #Method that emulates Socket addr return
      def addr
        #_, port, host, addr = 
    
        return nil, 80, 'localhost', '127.0.0.1'
      end
  end
 

  def setup
    Thread.current[:WEBrickSocket] = FakeWEBrickSocket.new
  end

  def test_myth         

    @rootContainer = UPnP::Service::Container.root_container

     myth = UPnP::Service::MythContainer.new('MythTV', '/home/yuchem/.mythtv/channels', 
                                  'octopus', 'mythconverg', 'mythtv', 'manatee')
    @rootContainer << myth
     
    myth.update '/some_service_path'
     
    xml = Builder::XmlMarkup.new :indent => 2, :encoding=>"utf-8"
    xml.instruct! :xml, :version=>"1.0", :encoding=>"utf-8"
    xml.container do |x|
      @rootContainer[3].each  {|i| i.to_xml(x)}
    end
  end
end
